#ifndef ETHCATDEVICE_H
#define ETHCATDEVICE_H

#include <string>
#include <thread>
#include <mutex>

using namespace std;

class SoemEtherCat;

enum SlaveState;

class EthCATDevice
{
public:
    EthCATDevice(uint32_t id , SoemEtherCat * soem_):
        Id(id),
        soemEtherCat_(soem_)
    {
        GetConstAttribut();
        GetDynamicAttribut();
    };

    ~EthCATDevice(){
    };

    void GetConstAttribut();

    void GetDynamicAttribut();

    void Refresh();

    void WriteState(SlaveState st);

    bool CheckAndSetState();

    void Reconfigure();

    void WriteOutput();

    int ReadInput();

    char* ReadPDO(int Idx, int SubIndex, int size);

    bool WritePDO(int Idx, int SubIndex, int size, char* buff);

    uint32_t Id;
    string Name;
    SlaveState State;
    unsigned short Delay;
    unsigned short Config_Address;
    uint32_t _ManufacturerId;
    string ManufacturerId;

    uint32_t _TypeId;
    string TypeId;

    uint32_t Revision;
    string MailboxProtocol;

    unsigned short InputSize{0};
    unsigned short OutputSize{0};

    char sExchange[1000];

    char* InputData;
    char* OutputData;

private:
    SoemEtherCat * soemEtherCat_;
    std::mutex mtx;  // 定义一个互斥锁
};

#endif // ETHCATDEVICE_H
